package znbkListRdqh.isNeedPaperAssembly;

import android.util.Log;

import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkListRdqh.fragment.WeekAscensionListFragment;
import znbkListXtfx.fragment.SystemReviewListFragment;

/**
 * Created by Administrator on 2018\4\19 0019.
 */

public class NeedPaperAssemblyPresenter implements ILoadDatePresenterAssembly {

    private ILoadDateViewAssembly view;
    private int ModelFrom;

    public NeedPaperAssemblyPresenter(ILoadDateViewAssembly view, int modelFrom) {
        this.view = (ILoadDateViewAssembly) view;
        this.ModelFrom = modelFrom;
    }

    @Override
    public void getData() {

        HttpOnNextListener<NeedPaperAssemblyResult> httpOnNextListener = new HttpOnNextListener<NeedPaperAssemblyResult>() {
            @Override
            public void onNext(NeedPaperAssemblyResult needPaperAssemblyResult) {

                if(needPaperAssemblyResult.isResult()){
                    //需要组卷
//                    ToastUtils.showShort("需要组卷");
                    view.assemblyPaper();
                }else{
                    //无需组卷
//                    ToastUtils.showShort("无需组卷");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        NeedPaperAssemblyApi api = null;
        if(ModelFrom==2) {
            api = new NeedPaperAssemblyApi(httpOnNextListener, (WeekAscensionListFragment) view);
        }else if(ModelFrom==1){
            api = new NeedPaperAssemblyApi(httpOnNextListener, (SystemReviewListFragment) view);
        }
        api.setModuleType(ModelFrom);
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

}
